

<template>
  <div>
    <basic-container>
      <avue-form-tabs :option="option" v-model="form" @change="handleChange" @submit="handleSubmit"></avue-form-tabs>
    </basic-container>
  </div>
</template>

<script>
/* eslint-disable */
import { mapGetters } from "vuex";
import crudMixin from '@/mixins/crud'
import options from "./options.js";
import { isNull, arr2pojo, obj2pojo, validateResponse } from "@/util/util";
import { successMsg, errorMsg } from "@/util/message"
import { field, reField } from "./field";

export default {
  name: "role",
  mixins: [crudMixin],
  components: {
  },
  data() {
    return {
      type: 'password',
      option: {
        column: [{
          label: '修改密码',
          prop: 'password',
          option: {
            submitText: '修改',
            column: [{
              label: '原密码',
              span: 12,
              row: true,
              type: 'password',
              prop: 'oldpassword',
              rules: [{
                      required: true,
                      message: "请输入密码",
                      trigger: "blur"
                  }, { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }],
            }, {
              label: '新密码',
              span: 12,
              row: true,
              type: 'password',
              prop: 'newpassword',
              rules: [{
                      required: true,
                      message: "请输入密码",
                      trigger: "blur"
                  },{ min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }],
            }, {
              label: '确认密码',
              span: 12,
              row: true,
              type: 'password',
              prop: 'newpasswords',
              rules: [{
                      required: true,
                      message: "请输入密码",
                      trigger: "blur"
                  },{ min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }],
            }]
          }
        }]
      },
      form: {},
    }
  },
  created() {
    this.handleWitch();
  },
  watch: {},
  mounted() { },
  computed: {
  },
  props: [],
  methods: {
    handleSubmit() {
      if (this.type === 'password')
      {
        if (this.form.newpassword !== this.form.newpasswords){
          return errorMsg(this,'新密码和确认密码不一致')
        }

        this.$store.dispatch('UpdatePassword',this.form).then(res => {
            if (res.data.status == 1)
            {
                return successMsg(this,'修改密码成功')
            }else{
                return errorMsg(this,res.data.message)
            }
        })
      }
    },
    handleWitch() {
      if (this.type === 'password')      {
        this.form = {
          oldpassword: '',
          newpassword: '',
          newpasswords: ''
        }
      }
    },
    handleChange(item) {
      this.type = item.prop;
      this.handleWitch();
    },
  }
};
</script>
